<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class Tickets {
    var $id;
    var $ticket_date;
    var $first_response;
    var $close_date;
    var $subject;
    var $description;
    var $due_date;
    var $user_create_id;
    var $priority_id;
    var $request_type_id;
    var $location_id;
    var $ticket_status_type_id;
     


    function open($id){
        global $db;
        $sql="select * from tickets where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->ticket_date=$ticket_date;
            $this->first_response=$first_response;
            $this->close_date=$close_date;
            $this->subject=$subject;
            $this->description=$description;
            $this->due_date=$due_date;
            $this->user_create_id=$user_create_id;
            $this->priority_id=$priority_id;
            $this->request_type_id=$request_type_id;
            $this->location_id=$location_id;
            $this->ticket_status_type_id=$ticket_status_type_id;

        }
    }

    function openAll(){
        $sql="select * from tickets order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into tickets values (null,'{$this->ticket_date}',
'{$this->first_response}',NULL,
'{$this->subject}','{$this->description}',
'{$this->due_date}','{$this->user_create_id}',
'{$this->priority_id}','{$this->request_type_id}',
'{$this->location_id}','{$this->ticket_status_type_id}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update tickets set ticket_date='{$this->ticket_date}',
first_response='{$this->first_response}',close_date='{$this->close_date}',
subject='{$this->subject}',description='{$this->description}',
due_date='{$this->due_date}',user_create_id='{$this->user_create_id}',
priority_id='{$this->priority_id}',request_type_id='{$this->request_type_id}',
location_id='{$this->location_id}',
ticket_status_type_id='{$this->ticket_status_type_id}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from tickets where id=".$this->id;
        $db->query($sql);
    }

}
?>
